// 栈实现队列
var MyQueue = function () {
  this.input = []
  this.output = []
}

/**
 * @param {number} x
 * @return {void}
 */
MyQueue.prototype.push = function (x) {
  this.input.push(x)
}

/**
 * @return {number}
 */
MyQueue.prototype.pop = function () {
  if (!this.output.length) {
    this.in2out()
  }
  return this.output.pop()
}

/**
 * @return {number}
 */
MyQueue.prototype.peek = function () {
  if (!this.output.length) {
    this.in2out()
  }
  return this.output[this.output.length - 1]
}

/**
 * @return {boolean}
 */
MyQueue.prototype.empty = function () {
  return this.input.length === 0 && this.output.length === 0
}

MyQueue.prototype.in2out = function () {
  //   for (let i = this.input.length - 1; i >= 0; i--) {
  //     this.output.push(this.input[i])
  //     this.input.pop()
  //   }
  while (this.input.length) {
    this.output.push(this.input.pop())
  }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */

let x = 1
var obj = new MyQueue()
obj.push(x)
var param_2 = obj.pop()
var param_3 = obj.peek()
var param_4 = obj.empty()
console.log(obj, param_2, param_3, param_4)
